<?php

// ##############################################################################||
// #                                                                 
// #   MySmartBB Version 1.7.0	                                      
// #   http://www.MySmartBB.com                                      
// #   Copyright (c) 2008 by MySmartBB team                           
// #   license http://opensource.org/licenses/gpl-license.php GNU Public License
// #                                                             
// #   filename : editreply.php                                            
// #   edit comments                                         
// #                                                                  
// ##############################################################################||

// ** General definitions **

     define('NOT_IN_INDEX',0);
     include('common.php');
     include('includes/SmartCode.js');
     include('includes/pager.php');

     if (!isset($_GET['page']) OR $_GET['page'] < 1)
     {
         $_GET['page'] = 1;
     }

     $page  = intval($_GET['page']);
     $start = ($info_row['perpage'] * ($page-1));

     $RP = new Pager($page);


     if ($_GET['edit'] == 1)
     {
         $SF->html_title_page('تحرير رد - (Powered By MySmartBB Universal)');

         if ($groupper_row['edit_own_reply'] != 1)
         {
             $SF->error('المعذرة، لا يمكنك تحرير المواضيع');
         }

         $id = intval($_GET['id']);
         $getsubjectinfo_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE id='$id'");
         $getsubjectinfo_row   = $DB->sql_fetch_array($getsubjectinfo_query);

         if ($getsubjectinfo_row['writer'] != $member_row['username'])
         {
             $SF->error('المعذرة، لايمكنك تحرير هذا الرد');
         }

         if ($groupper_row['admincp_allow'] != 1)
         {
             $time_out = $info_row['time_out']*60;
             if ($now > $getsubjectinfo_row['write_time']+$time_out)
             {
                 $SF->error('انتهى الوقت المحدد للتعديل<br /><br /> الوقت المحدد للتعديل هو ' . $info_row['time_out'] . ' دقيقة');
             }
         }

         if ($_GET['index'] == 1)
         {
             $icons_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type<>'0' AND smile_path<>'" . $getsubjectinfo_row['icon'] . "' ORDER BY id DESC");

             $icons_row = array();
             while ($icon_row = $DB->sql_fetch_array($icons_query))
             {
                 $icons_row[] = $icon_row;
                 $Smarty->assign('icons_row',$icons_row);
             }

             $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");

             $smiles_row = array();
             while ($smile_row = $DB->sql_fetch_array($smiles_query))
             {
                 $smiles_row[] = $smile_row;
                 $Smarty->assign('smiles_row',$smiles_row);
             }

			$text = stripslashes($getsubjectinfo_row['text']);
			$text = htmlspecialchars($text);

             $Smarty->assign('is_reply',1);
             $Smarty->assign('text',$text);
             $Smarty->assign_by_ref('getsubjectinfo_row',$getsubjectinfo_row);
             $SF->GetSmartCode();

             $subject_query = $DB->sql_query("SELECT id,title FROM " . $db_prefix . "subject WHERE id = '".$getsubjectinfo_row['subject_id']."'");
             $subject_row = $DB->sql_fetch_array($subject_query);

             $section_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$getsubjectinfo_row['section']."'");
             $section_row = $DB->sql_fetch_array($section_query);

             if ($section_row['sub_section'] == 1)
             {
                 $getmainsection_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$section_row['from_sub_section']."'");
                 $getmainsection_row   = $DB->sql_fetch_array($getmainsection_query);
                 $Smarty->assign('path_bar',"<a href=forum.php?show=1&id=".$getmainsection_row['id'].">".$getmainsection_row['title']."</a> -> <a href=forum.php?show=1&id=".$section_row['id'].">".$section_row['title']."</a> -> <a href=show.php?main=1&id=".$subject_row['id'].">".$subject_row['title']."</a> -> تحرير رد");
             }
             else
             {
                 $Smarty->assign('path_bar',"<a href=forum.php?show=1&id=".$section_row['id'].">".$section_row['title']."</a> -> <a href=show.php?main=1&id=".$subject_row['id'].">".$subject_row['title']."</a> -> تحرير رد");
             }

             $Smarty->display('path-bar.tpl');
             $temp = md5(time());
             $Smarty->assign('temp',$temp);
             $Smarty->display('post_edit-subject-and-reply.tpl');
             $Smarty->display('footer.tpl');

         }
         elseif ($_GET['start'] == 1)
         {
             if (strlen(trim($_POST['T1'])) > $info_row['post_title_max'])
             {
                 $SF->error('عدد حروف عنوان الرد أكثر من (' . $info_row['post_title_max'] . ') حرف');
             }

             if (strlen(trim($_POST['S1'])) > $info_row['post_text_max'])
             {
                 $SF->error('عدد حروف الرد أكثر من (' . $info_row['post_text_max'] . ') حرف');
             }

             if (strlen(trim($_POST['S1'])) < $info_row['post_text_min'])
             {
                 $SF->error('عدد حروف الرد أقل من (' . $info_row['post_text_min'] . ') حرف');
             }

             $subject_query = $DB->sql_query("SELECT id FROM " . $db_prefix . "subject WHERE id = '".$getsubjectinfo_row['subject_id']."'");
             $subject_row = $DB->sql_fetch_array($subject_query);
	     $update = $DB->sql_query("UPDATE " . $db_prefix . "reply SET title='" . $_POST['T1'] . "',text='" . $_POST['S1'] . "',icon='" . $_POST['R1'] . "',action_by='" . $SF->SafeSQL($member_row['username']) . "',actiondate=now(),subscribe='" . $_POST['subs'] . "',edit_reason='" . $_POST['T9'] . "' WHERE id='$id'");

             if ($update)
             {
                 $RP->SetPagerN($info_row['subject_perpage'],$DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id='" . $subject_row['id'] . "' AND  delete_topic <> 1")));

                 $page  = explode('|',$RP->PageNum_source());
                 $start = $page[0];
                 $page  = $page[1]-1;

                 if (empty($start) or empty($page))
                 {
                     $start = 0;
                     $page  = 0;
                 }

                 $updateforums  =  $SF->UpdateForumsArray();

                 if ($updateforums)
                 {
					$Smarty->assign('msgg','حُدّثَت المعلومات بنجاح'); 
                	$Smarty->assign("GO","show.php?main=1&id=" . $getsubjectinfo_row['subject_id'] . "&start=" . $start . "&page=" . $page ."#" . $id);
					$SF->go_to("show.php?main=1&id=" . $getsubjectinfo_row['subject_id'] . "&start=" . $start . "&page=" . $page . "#" . $id,2);                  
                    $Smarty->display('loading.tpl');
                    $Smarty->display('footer.tpl');
                 }
             }
         }

     }

?>